<template>
  <!--  #ifdef APP-PLUS || APP || APP-ANDROID || APP-IOS -->
  <uv-button @click="checkUpdate">检查更新</uv-button>
  <!--  #endif -->
  <uv-button @click="loginOut">登出</uv-button>
</template>

<script setup lang="ts">
import { useCommonServiceHooks } from "@/config/CommonServiceHooks";
import { useCommonStore } from "@/config/CommonStore";
import { useLoginStore } from "@/pages/login/loginStore"
import { storeToRefs } from "pinia"
import {baseApi, version} from "@/MyEnv"
import { type CheckUpdateVO } from "@/config/CommonTypes";
import { type R } from "@/types/R";
import { request } from "@/utils/Request";

let loginStore = useLoginStore()
let {aToken} = storeToRefs(loginStore)

let {appUpdate} = useCommonServiceHooks();
let commonStore = useCommonStore()
let {appConfigVO} = storeToRefs(commonStore)


const checkUpdate = async()=>{
  // #ifdef APP-PLUS
  if(version != appConfigVO.value?.appNowVersion.android.versionStr){
    // 需要更新
    let r:R<CheckUpdateVO> = await request.post("/app/appBase/checkUpdate", {
      platform: "Android",
      nowVersion: version,
      updateVersion: appConfigVO.value?.appNowVersion.android.versionStr
    })
    let checkUpdateVO:CheckUpdateVO = r.data;

    appUpdate(appConfigVO.value?.appNowVersion!, checkUpdateVO);
  }
  // #endif
}

const loginOut = ()=>{
  aToken.value = undefined
  uni.reLaunch({url: "/pages/login/login"})
}

</script>

<style scoped></style>